#!/bin/sh

# hapus-jagasama
# menghapus jagasama
# harus root

CONFIG_FILE=/etc/jagasama.conf
read_config()
{
	awk -v MKEY=$1 '{
	i = index($0, "#");
	if (i){ Str=substr($0,1, i-1); }
	else { Str = $0; }
	if (Str ne "")
	{
		#print MKEY;
		split (Str, A);
		if (A[1] == MKEY) { gsub(","," ",A[2]); print A[2]; exit; }
	}
	}' $CONFIG_FILE
}


if [ `whoami` != root ]
then
	echo harus root untuk menjalankan aplikasi ini
	exit
fi

simpandir=`read_config SAVEDIR`
rm -fr $simpandir/jagasama
for i in 1 2 3 4 5
do
rm -f /etc/rc$i.d/S99jagasama
done
rm -f /etc/init.d/jagasama
rm -f /usr/sbin/jagasama

the_users=`read_config USERS`
for n in $the_users
do
awk '{
	if (index(tolower($0),"jagasama")==0)
	{
		print $0;
	}
}' /home/$n/.profile > /tmp/profile
mv /tmp/profile /home/$n/.profile
chown $n:$n /home/$n/.profile
done

rm -f $CONFIG_FILE

